﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<link rel="stylesheet" type="text/css" media="screen" href="css/jquery-ui-1.8.1.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />
<script src="js/jquery-1.5.2.min.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-cn.js" type="text/javascript"></script>
<script src="js/json2.js" type="text/javascript"></script>
<script src="js/xing.js" type="text/javascript"></script>
<script type="text/javascript">
	$.jgrid.no_legacy_api = true;
	$.jgrid.useJSON = true;
</script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script type="text/javascript">
var firstLoad = true;
var myStreets = [];
var udistrict, usid, this_year;

function searchCustomer() {
	var district = $("#sf_district").val();
	var sid = $("#sf_street").val();
	var commuid = $("#sf_community").val();
	var ctype = $("#sf_ctype").val();
	var cid   = $("#sf_cid").val();
	var idcard = $("#sf_idcard").val();
	var cname = $("#sf_cname").val();
	var cage  = $("#sf_cage").val();
	var specneed = $("#sf_specneed").attr("checked");
	
	var q = "action=4&isquit=0&sf_district=" + district + "&sf_street=" + sid + "&sf_community=" + commuid + "&sf_ctype=" + ctype
			+ "&sf_specneed=" + specneed + "&sf_cid=<" + cid + ">&sf_idcard=<" + idcard + ">&sf_cname=" + escape(cname) + "&sf_cage=>" + cage;

	if (this.id == "sf_submit")
		jQuery("#list1").jqGrid('setGridParam',{page:1,url:"main?" + q}).trigger("reloadGrid");
	else
		$("#df").attr("src","main?oper=excel&" + q); 
}

function sfDistrictChange() {
	if (usid != "0") {
		$("#sf_district").val(udistrict);
		$("#sf_street").html("<option value='0'>全  部</option>" + initStreet(udistrict));
		sfStreetChange();
		return;
	}
	
	var district = $("#sf_district").val();
	
	if (district == "0") {
		$("#sf_street").html("<option value='0'>选择街道</option>");
	} else {
		$("#sf_street").html("<option value='0'>全  部</option>" + initStreet(district));
		$("#sf_street").val("0");
	}
	$("#sf_community").html("<option value='0'>选择社区</option>");
}

function sfStreetChange() {
	if (usid != "0") {
		$("#sf_street").val(usid);
	}
	
	var sid = $("#sf_street").val();
	
	if ((sid == null) || (sid.length == 1)) {
		$("#sf_community").html("<option value='0'>选择社区</option>");
	} else {
		$("#sf_community").html("<option value='0'>全  部</option>" + initCommunity(sid));
	}
}

function loadStreetCommunity() {
	$.get('base?action=12',function (data, textStatus){
		$.extend(true, myStreets, data);
	});
}

function initStreet(district) {
	var ops = "";
	for (i = 0; i < myStreets.length; i++) {
		if (myStreets[i].district != district)
			continue;
		ops += "<option value='" + myStreets[i].sid + "'>" + myStreets[i].sid + "|" + myStreets[i].sname + "</option>";
	}
	return ops;
}

function districtChange() {
	if (usid != "0") {
		$("#district").val(udistrict);
		$("#sid").html(initStreet(udistrict));
		streetChange();
		return;
	}
	
	var district = $('#district').val();
	$("#sid").html(initStreet(district));
	var sid = $("#sid").val();
	$("#commuid").html(initCommunity(sid));
};

function streetChange() {
	if (usid != "0") {
		$("#sid").val(usid);
	}
	
	var sid = $('#sid').val();
	$("#commuid").html(initCommunity(sid));
}

function initCommunity(sid) {
	var ops = "";
	for (var i = 0; i < myStreets.length; i++) {
		if (myStreets[i].sid != sid) 
			continue;
		var cs = myStreets[i].communitys;
		
		for (var j = 0; j < cs.length; j++) {
			ops += "<option value='" + cs[j].cid + "'>" + cs[j].cid + "|" + cs[j].cname + "</option>";
		}
	}

	return ops;
};

function checkValue(postdata, formid) {
	var residence = postdata.residence;
	var caddress = postdata.caddress;
	if (residence.length > 40) {
		return [false,"户口所在地的长度不能超过40"];
	}
	
	if (caddress.length > 40) {
		return [false,"住址的长度不能超过40"];
	}
	
	var csex = postdata.csex;
	var idcard = postdata.idcard;
	if (idcard.length != 20) {
		return [false, "残疾证号码长度需要20位！"];
	}
	
	var age = parseInt(this_year) - parseInt(idcard.substring(6, 10));
	if (csex == 'F') {  //女
		if (parseInt(idcard[16]) % 2 == 1)
			return [false, "录入性别女，与残疾证号码不符！"];
		if (age > 55)
			return [false, "女性年龄需小于55岁！"];
	} else if (csex == 'M') { //男
		if (parseInt(idcard[16]) % 2 == 0)
			return [false, "录入性别男，与残疾证号码不符！"];
		if (age > 60)
			return [false, "男性年龄需小于60岁！"];
	}
	
	//postdata.cursum = $.trim(postdata.cursum);
	if (postdata.ctype == "1")
		postdata.subsidy = "50";
	else if (postdata.ctype == "2")
		postdata.subsidy = "50";
	else
		postdata.subsidy = "30";
	postdata.cid = $.trim(postdata.cid);
	
	if (postdata.cid.length != 13) {
		return [false,"人员编号的长度必须是13位"];
	}
	
	return [true,""];
};

function setGridButton() {
	if ((!firstLoad) || (udistrict == "0"))
		return;
		
	jQuery("#list1").jqGrid('navGrid','#gridpager1',{edit:false,add:false,del:false,refresh:false,search:false})
		.jqGrid('navButtonAdd','#gridpager1',{
   		caption:"添加", 
   		buttonicon:"ui-icon-plus", 
   		onClickButton: function(){
				jQuery("#list1").jqGrid('editGridRow','new',{
					addCaption:"添加三无/低保人员信息",
					dataheight:400,
					bSubmit:"保存",modal: true, 
					closeAfterAdd:true, 
					reloadAfterSubmit:true,
					beforeSubmit:checkValue,
					beforeShowForm: function(formid) {
						$('#cid').attr("readonly",false);
						$('#district').val(udistrict);
						$("#sid").html(initStreet(udistrict));
						if (usid != "0") $("#sid").val(usid);
						$("#commuid").html(initCommunity($("#sid").val()));
						$('#tr_subsidy', formid).hide();
					},
					afterSubmit : function(r, postdata) {
				  					var data = eval('(' + r.responseText + ')');
				  					switch (data.code) {
			  							case 0: return [true, ""]; break;
			  							case 30000: return [false, "添加失败，人员编码不能重复！"]; break;
			  							case 30001: return [false, "添加失败，人员身份证号码不能重复！"]; break;
			  							default: return [false, data.message];
			  						}
				  }
				}); 
			}
		})
		.jqGrid('navButtonAdd','#gridpager1',{
   		caption:"更改", 
   		buttonicon:"ui-icon-wrench", 
   		onClickButton: function(){
				var gr = jQuery("#list1").jqGrid('getGridParam','selrow');
				if( gr != null )
				  jQuery("#list1").jqGrid('editGridRow',gr,{
				  	editCaption:"修改三无/低保人员信息",
				  	dataheight:400,
				  	bSubmit:"保存",modal: true,
				  	closeAfterEdit:true,
				  	viewPagerButtons:false, 
				  	reloadAfterSubmit:true,
				  	beforeSubmit:checkValue,
				  	beforeShowForm:function(formid) {
				  		$('#cid').attr("readonly",true);
				  		$("#sid").html(initStreet($("#district").val()));
				  		var sid = jQuery("#list1").jqGrid('getCell', gr, 12);
				  		$("#sid").attr("value", sid);
				  		$("#commuid").html(initCommunity(sid));
				  		var commuid = jQuery("#list1").jqGrid('getCell', gr, 13);
				  		$("#commuid").attr("value", commuid);
				  		$('#tr_subsidy', formid).hide();
				  	},
				  	afterSubmit : function(r, postdata) {
				  					var data = eval('(' + r.responseText + ')');
				  					switch (data.code) {
			  							case 0: return [true, data.message]; break;
			  							case 30000: return [false, "修改失败，人员编码不能重复！"]; break;
			  							case 30001: return [false, "修改失败，人员身份证号码不能重复！"]; break;
			  							default: return [false, data.message];
			  						}
				  	}
				  });
				else
					showTips("请选择要修改的三无/低保人员");
			}
		})
		.jqGrid('navButtonAdd','#gridpager1',{
   		caption:"删除", 
   		buttonicon:"ui-icon-close", 
   		onClickButton: function(){
				var gr = jQuery("#list1").jqGrid('getGridParam','selrow');
				var cname = jQuery("#list1").jqGrid('getCell', gr, 1);
				if( gr != null )
				  jQuery("#list1").jqGrid('delGridRow', gr, {
				  				caption:"确定要将该残疾人员删除吗?", 
				  				msg:"将人员'" + cname + "'删除之前\n<b>必须先删除该残疾人员已分配的任务</b>",
				  				top: 200,
				  				left: 400,
				  				modal: true,
				  				closeAfterEdit:true, 
				  				reloadAfterSubmit:true,
				  				afterSubmit : function(r, postdata) {
				  					var data = eval('(' + r.responseText + ')');
				  					if (data.code != 0)
				  						return [false, data.message];
				  					else
				  						return [true, data.message];
				  				}
				  			});
				else
					showTips("请选择要删除的人员");
			}
		})
		.jqGrid('navSeparatorAdd','#gridpager1',{})
		.jqGrid('navButtonAdd','#gridpager1',{
   		caption:"批量添加", 
   		buttonicon:"ui-icon-plusthick", 
   		onClickButton: function(){
				jQuery("#list1").jqGrid('editGridRow','new',{
					addCaption:"批量添加三无/低保人员信息",
					dataheight:400,
					bSubmit:"保存",modal: true,
					clearAfterAdd:false,
					closeAfterAdd:false, 
					reloadAfterSubmit:false,
					beforeSubmit:checkValue,
					beforeShowForm: function(formid) {
						$('#cid').attr("readonly",false);
						$('#district').val(udistrict);
						$("#sid").html(initStreet(udistrict));
						$("#commuid").html(initCommunity($("#sid").val()));
						$('#tr_subsidy', formid).hide();
					},
					afterSubmit : function(r, postdata) {
				  					var data = eval('(' + r.responseText + ')');
				  					switch (data.code) {
			  							case 0: alert("人员添加成功！"); return [true, ""]; break;
			  							case 30000: return [false, "添加失败，人员编码不能重复！"]; break;
			  							case 30001: return [false, "添加失败，人员身份证号码不能重复！"]; break;
			  							default: return [false, data.message];
			  						}
				  }
				}); 
			}
		});
	firstLoad = false;
}

function setGrid() {
	jQuery("#list1").jqGrid({ 
			url:'main?action=4&isquit=0',
			hidegrid: "false",
			datatype: "json",
			colNames:['人员编号','姓名','性别','特需','残疾类别','残疾等级','评估分数','残疾证号','家庭人数','住址','户口所在地','所属区','所属街道','所属社区','身体状况','账户余额','补贴金额','资金来源','住房状况','培训需求','就业需求','康复需求','生活保障形式','养老','医疗','服务次数','托养服务类别','手机号码','固定电话','加入日期'],
			colModel:[ 
					{name:'cid', width:100, sortable:false, align:'right',editable:true,editoptions:{size:20,maxlength:13},editrules:{number:true,required:true}}, 
					{name:'cname', width:40, sortable:false, align:'right', editable:true,editoptions:{size:8,maxlength:4},editrules:{required:true}},
					{name:'csex',width:30, sortable:false, align:'right', editable:true,edittype:"select", formatter:'select', editoptions:{value:"F:女;M:男"}},
					{name:'specneed', width:30, sortable:false, align:'right', editable:true,edittype:"checkbox",formatter:'checkbox',editrules:{required:true},editoptions: {value:"true:false"}},
					{name:'ctype',width:60, sortable:false, align:'right', editable:true,edittype:"select", formatter:'select', editoptions:{value:"1:视力残疾;2:听力残疾;3:言语残疾;4:肢体残疾;5:智力残疾;6:精神残疾;7:多重残疾"}},
					{name:'level',width:50, sortable:false, align:'right', editable:true,edittype:"select", formatter:'select', editoptions:{value:"1:一级;2:二级;3:三级;4:四级"}},
					{name:'evalvalue',width:50, sortable:false, align:'right', editable:true, formatter:'integer', editoptions:{size:3,maxlength:3},editrules:{required:true}},
					{name:'idcard', width:140, sortable:false, align:'right', editable:true,editoptions:{size:24,maxlength:20},editrules:{required:true}},
					{name:'family', width:50, sortable:false, align:'right', editable:true,editoptions:{size:6,maxlength:1},editrules:{number:true,required:true}},
					{name:'caddress',width:160, sortable:false, align:'right',editable:true,edittype:"textarea",editoptions:{rows:"2",cols:"24"},editrules:{required:true}},
					{name:'residence', width:160, sortable:false, align:'right', editable:true,edittype:"textarea",editoptions:{rows:"2",cols:"24"},editrules:{required:true}},
					{name:'district',width:50, sortable:false, align:'right', editable:true,formatter:'select',edittype:"select", editoptions:{value:"1:市辖区;2:桥东区;3:桥西区;4:高新区;5:宣化区;6:下花园区"}},
					{name:'sid', width:50, sortable:false, align:'right', hidden:true, editable:true,editrules:{required:true,edithidden:true},edittype:"select", editoptions:{value:"0:选择街道"}},
					{name:'commuid', width:80, sortable:false, align:'right', hidden:true,editable:true,editrules:{required:true,edithidden:true},edittype:"select", editoptions:{value:"0:选择社区"}},
					{name:'health', width:60, sortable:false, align:'right', editable:true,editoptions:{size:6,maxlength:4},editrules:{required:true}},
					{name:'cursum', width:50, sortable:false, align:'right'},
					{name:'subsidy', width:50, sortable:false, align:'right', editable: true},
					{name:'zjly',width:50, sortable:false, align:'right', editable:true,edittype:"select", formatter:'select', editoptions:{value:"1:中央;2:省级;3:市级;4:县区级"}},
					{name:'zfzk',width:50, sortable:false, align:'right', editable:true,edittype:"select", formatter:'select', editoptions:{value:"1:无房;2:危房;3:良好"}},
					{name:'peixun', width:50, sortable:false, align:'right', editable:true,edittype:"checkbox",formatter:'checkbox',editrules:{required:true},editoptions: {value:"true:false"}},
					{name:'jiuye', width:50, sortable:false, align:'right', editable:true,edittype:"checkbox",formatter:'checkbox',editrules:{required:true},editoptions: {value:"true:false"}},
					{name:'kangfu', width:50, sortable:false, align:'right', editable:true,edittype:"checkbox",formatter:'checkbox',editrules:{required:true},editoptions: {value:"true:false"}},
					{name:'bzxs',width:50, sortable:false, align:'right', editable:true,edittype:"select", formatter:'select', editoptions:{value:"1:五保;2:低保;3:集中托养;4:亲属供养;5:无保障"}},
					{name:'yanglao',width:50, sortable:false, align:'right', editable:true,edittype:"select", formatter:'select', editoptions:{value:"1:新农合;2:城镇居民;3:无保险;4:其他"}},
					{name:'yiliao',width:50, sortable:false, align:'right', editable:true,edittype:"select", formatter:'select', editoptions:{value:"1:新农合;2:无保险;3:其他"}},
					{name:'servnum', width:70, sortable:false, align:'right', hidden:true},
					{name:'tylb',width:80, sortable:false, align:'right', editable:true,edittype:"select", formatter:'select', editoptions:{value:"1:一类;2:二类;3:三类"}},
					{name:'cmobile', width:70, sortable:false, align:'right', editable: true, editoptions:{size:18,maxlength:11},editrules:{number:true}},
					{name:'ctel', width:70, sortable:false, align:'right', editable: true, editoptions:{size:18,maxlength:11},editrules:{number:true}},
					{name:'shiftdate', width:70, sortable:false, align:'right'}
			], 
			viewrecords: true,
			rowNum:20,
			pager: '#gridpager1',
			height: 460,
			editurl:'main?action=4&isquit=0',
			caption:"残疾人员信息",
			footerrow: true,
			userDataOnFooter: true,
			gridComplete: function() {
				udistrict = jQuery("#list1").jqGrid('getGridParam', 'userData')["udistrict"];
				usid = jQuery("#list1").jqGrid('getGridParam', 'userData')["usid"];
				this_year = jQuery("#list1").jqGrid('getGridParam', 'userData')["this_year"];
				setGridButton();
				if (usid != "0") {
					$("#sf_district").val(udistrict);
					sfDistrictChange();
				}
			}
	})}; 
	
	$(document).ready(function(){
		loadStreetCommunity();
		setGrid();
		$("#sf_submit").click(searchCustomer);
		$("#sf_excel").click(searchCustomer);
		$("#district").live('change', districtChange);
		$("#sid").live('change', streetChange);
		$("#sf_street").live('change', sfStreetChange);
	});
</script>

<body style="background-color:#d9f1cc;">
                <iframe id="df"  name="df" src="" width=0 height=0 frameborder="0" ></iframe>
                <form id="sf" action="main">
                	<table>
                	<tr>
	                	<td>选择所属区</td>
	                	<td><select id="sf_district" name="sf_district" onChange="sfDistrictChange()">
		                		<option value="0" selected>全  市</option>
		                		<option value="1">市辖区</option>
		                		<option value="2">桥东区</option>
		                		<option value="3">桥西区</option>
		                		<option value="4">高新区</option>
		                		<option value="5">宣化区</option>
		                		<option value="6">下花园区</option>
		                	</select></td>
	                	<td>  街道办事处 </td>
	                	<td><select id="sf_street" name="sf_street">
	                								<option value='0'>选择街道</option>
	                						 </select></td>
	                	<td>  编号(*)</td>
	                	<td><input type="text" id="sf_cid" name="sf_cid" size="22" maxlength="13"/></td>
	                	<td>  姓名</td>
	                	<td><input type="text" id="sf_cname" name="sf_cname" size="14" maxlength="4"/></td>
	                	<td><input type="button" id="sf_submit" value="查 询"></td>
			            </tr>
			          	<tr>
			          		<td>居委会</td>
	                	<td><select id="sf_community" name="sf_community"/>
	                						<option value='0'>选择社区</option>
	                				 </select></td>
	                	<td>  人员类型</td>
	                	<td><select id="sf_ctype" name="sf_ctype">
			                		<option value="0">全  部</option>
			                		<option value="1">视力残疾</option>
			                		<option value="2">听力残疾</option>
			                		<option value="3">言语残疾</option>
			                		<option value="4">肢体残疾</option>
			                		<option value="5">智力残疾</option>
			                		<option value="6">精神残疾</option>
			                		<option value="7">多重残疾</option>
			                	</select></td>
	                	<td>残疾证(*)</td>
	                	<td><input type="text" id="sf_idcard" name="sf_idcard" size="22" maxlength="20"/></td>
	                	<td>年龄</td>
	                	<td><input type="text" id="sf_cage" name="sf_cage" size="5" maxlength="3"/>&nbsp
	                		  仅特需<input type="checkbox" id="sf_specneed" name="sf_specneed"></td>
	                	<td><input type="button" id="sf_excel" value="导 出"></td>
                	</tr>
                	</table>
                	</form>
            
				<div id="RightPane"  >
					<div class="innertube">
					<table id="list1"></table>
					<div id="gridpager1"></div>
				</div>
				</div>


</body>
